// 2025.03.26 昨天 开始 收捡 蚕 出了 十来个 就是 桑叶 也才 出 三两片嫩芽

import { createApp } from 'vue';
import { addEvent } from '../../../../../../global/element/Event/Func/add_remove_eventListen';
import {
  normalizeContainer,
  packNode,
} from '../../../../../../global/element/Func';
import { focusDisplay_comps_add_operate } from './comps/focusDisplay_operate_comps/Classes/focusDisplay_comps_add_operate/cla_focusDisplay_comps_add_operate';
import { temp_container } from '../../../../../DataDefine/sourceData';
import { create_static_focusDisplay_mana } from '../../../../../globalComps/comps/focusDisplay';
import { win_static_namespace__fd_comps_add } from './comps/focusDisplay_operate_comps/DataDefine/sourceData';

/**
 * 添加组件设置 元素 id
 */
const add_unf_icon_id = 'au_icon';

/**
 * 添加组件设置 元素
 * @type {HTMLElement}
 */
let add_unf_icon_el;

/**
 * 全局 焦点元素 管理
 */
let win_static_focusDisplay = create_static_focusDisplay_mana(
  win_static_namespace__fd_comps_add
);

function init_aunf() {
  add_unf_icon_el = normalizeContainer(add_unf_icon_id);
  addEvent(add_unf_icon_el, 'click', display_addNewUniComp);
}

function display_addNewUniComp() {
  let focusDisplay_operate =
    win_static_focusDisplay.getOrCreate_focusDisplay_dom();

  let comp = 'focusDisplay_operate_comps';

  import(`./comps/${comp}/${comp}.vue`).then((mod) => {
    let app = createApp(mod.default);
    app.mount(temp_container);
    // console.log(132);
    let focusDom_frame_nodeArr = normalizeContainer(temp_container).children;
    focusDisplay_operate.targetEl.firstChild.innerHTML = '';
    do {
      packNode(
        focusDisplay_operate.targetEl.firstChild,
        focusDom_frame_nodeArr[0] || focusDom_frame_nodeArr
      );
    } while (focusDom_frame_nodeArr.length > 0);
    // console.log(132);
    app.unmount();

    let foc_obj = new focusDisplay_comps_add_operate();

    foc_obj.display_dialog();
  });
}

// /**
//  * 暂且 每次 重新 写  因为 他的 dongtaiimport 不支持 长 链接 /${comp_src_link}/${comp_src_link}.vue
//  * @param {string} comp_src_link 'focusdisplay' 只用填这个 就能 调用
//  * @returns {HTMLCollection}
//  */
// function dynamic_import_get_domArr_cur(comp) {
//   import(`./comps/${comp}/${comp}.vue`).then((mod) => {
//     createApp(mod.default).mount(temp_container);
//   });

//   return normalizeContainer(temp_container).children;
// }

export { init_aunf };
